//
//  UIButton+JWTabbar.m
//  TimeManagement
//
//  Created by ytkjs2 on 2020/2/25.
//  Copyright © 2020 ytk. All rights reserved.
//

#import "UIButton+JWTabbar.h"


@implementation UIButton (JWTabbar)

- (void) setImage:(UIImage *)image withTitle:(NSString *)title forState:(UIControlState)stateType {
    
    CGSize titleSize = [title sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:11]}];
    
    [self.imageView setContentMode:UIViewContentModeCenter];
    
    [self setImageEdgeInsets:UIEdgeInsetsMake(0, 0.0, 20.0, -titleSize.width)];
    
    [self setImage:image forState:stateType];
    
    [self.titleLabel setContentMode:UIViewContentModeCenter];
    
    [self.titleLabel setBackgroundColor:[UIColor clearColor]];
    
    [self.titleLabel setFont:[UIFont systemFontOfSize:11]];
    
    [self.titleLabel setTextColor:[UIColor whiteColor]];
    
    [self setTitleEdgeInsets:UIEdgeInsetsMake(30.0, -image.size.width, 0.0, 0.0)];
    
    [self setTitle:title forState:stateType];

}

@end
